package testGroovy

import groovy.json.JsonParserType
import groovy.json.JsonSlurper
import groovy.json.StringEscapeUtils

def str = $/
{"flowId":"7a8ae52c-7370-49fd-8972-085ddcb09b41","resultCode":"C0000","insured":[
        {
            "name":"insured.name",
            "text": "被保人姓名",
            "value":"陈跃军",
            "type": "text",
            "regex" : "^(?:[\u4e00-\u9fa5\u3400-\u4db5\u9fa6-\u9fbb\uf900-\uFA6A\uE815-\uE864·]|[a-zA-Z\s]){1,40}$"
        },
        {
            "name":"insured.idType",
            "text": "证件类型",
            "value":"",
            "type": "select",
            "option":[
                {"text":"居民身份证","value":"01"},
                {"text":"护照","value":"02"},
                {"text":"军官证","value":"03"},
                {"text":"驾驶证","value":"05"},
                {"text":"港澳回乡证或台胞证","value":"06"}
        ],
            "regex" : "^01|02|03|05|06$"
        },
        {
            "name":"insured.idNo",
            "text": "证件号码",
            "value":"",
            "type": "text",
            "regex" : ""
        },
        {
            "name":"insured.birthday",
            "text": "生日",
            "value":"",
            "type": "text",
            "regex":"^(((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29)))?$"
        },
        {
            "name":"insured.gender",
            "text": "性别",
            "value":"",
            "type": "radio",
            "option":[
                {"text":"男","value":"M"},
                {"text":"女","value":"F"}
        ],
            "regex" : "^[MF]$"
        },
        {
            "name":"insured.mobile",
            "text": "手机号",
            "value":"",
            "type": "text",
            "regex":"^((13|14|15|17|18)(\d)(\*\*\*\*|\d{4})(\d{4,5}))?$"
        },
        {
            "name":"insured.email",
            "text": "E-mail",
            "value":"",
            "type": "text",
            "regex" : "^[\w\-\.]+@[a-zA-Z0-9]+(\-[a-zA-Z0-9]+)?(\.[a-zA-Z0-9]+(\-[a-zA-Z0-9]+)?)*\.[a-zA-Z]{2,4}$"
        },
        {
            "name":"insured.provinceCode",
            "text": "被保人省份",
            "value":"",
            "type": "select",
            "option":[
                {"text":"请选择","value":""}
        ]
        },
        {
            "name":"insured.cityCode",
            "text": "被保人城市",
            "value":"",
            "type": "select",
            "option":[
                {"text":"请选择","value":""}
        ]
        },
        {
            "name":"insured.areaCode",
            "text": "被保人区县",
            "value":"",
            "type": "select",
            "option":[
                {"text":"请选择","value":""}
        ]
        },
        {
            "name":"insured.address",
            "text": "被保人地址",
            "value":"",
            "type": "select",
            "option":[
                {"text":"请选择","value":""}
        ]
        }
],"q2Info":[
],"address":[
        {
            "name":"address.name",
            "text": "收单人姓名",
            "value":"",
            "type": "text"
        },
        {
            "name":"address.mobile",
            "text": "收单人手机",
            "value":"",
            "type": "text"
        },
        {
            "name":"department.provinceName",
            "text": "省份",
            "value":"320000",
            "type": "select",
            "option":[
                {"text":"江苏省","value":"320000"}
        ]
        },
        {
            "name":"department.cityName",
            "text": "城市",
            "value":"320100",
            "type": "select",
            "option":[
                {"text":"南京市","value":"320100"}
        ]
        }
        ,{
            "name":"department.townCityCode",
            "text": "县级市",
            "value":"",
            "type": "select",
            "option":[
            {"text":"请选择","value":""}
            ,{"text":"玄武区","value":"320102"}
            ,{"text":"白下区","value":"320103"}
            ,{"text":"秦淮区","value":"320104"}
            ,{"text":"建邺区","value":"320105"}
            ,{"text":"鼓楼区","value":"320106"}
            ,{"text":"下关区","value":"320107"}
            ,{"text":"浦口区","value":"320111"}
            ,{"text":"栖霞区","value":"320113"}
            ,{"text":"雨花台区","value":"320114"}
            ,{"text":"江宁区","value":"320115"}
            ,{"text":"六合区","value":"320116"}
            ,{"text":"溧水县","value":"320124"}
            ,{"text":"高淳县","value":"320125"}
            ,{"text":"大厂区","value":"320112"}
            ,{"text":"高新区","value":"320126"}
    ]
        }
        ,{
            "name":"address.detail",
            "text": "收单人地址",
            "value":"",
            "type": "text"
        }
        ,{
            "name":"address.storeExtractFlag",
            "text":"门店自取标示",
            "value":"",
            "type":"radio"
        }
],"tjTax":[

        {}
],"applicant":[
        {
            "name":"applicant.name",
            "text": "姓名",
            "value":"",
            "type": "text",
            "regex":"^(?:[\u4e00-\u9fa5\u3400-\u4db5\u9fa6-\u9fbb\uf900-\uFA6A\uE815-\uE864·]|[a-zA-Z\s]){1,40}$"
        },
        {
            "name":"applicant.idType",
            "text": "证件类型",
            "value":"",
            "type": "select",
            "option":[
                {"text":"居民身份证","value":"01"},
                {"text":"护照","value":"02"},
                {"text":"军官证","value":"03"},
                {"text":"驾驶证","value":"05"},
                {"text":"港澳回乡证或台胞证","value":"06"}
        ],
            "regex":"^01|02|03|05|06$"
        },
        {
            "name":"applicant.idNo",
            "text": "证件号码",
            "value":"",
            "type": "text",
            "regex":""
        },
        {
            "name":"applicant.birthday",
            "text": "生日",
            "value":"",
            "type": "text",
            "regex":"^(((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29)))?$"
        },
        {
            "name":"applicant.gender",
            "text": "性别",
            "value":"",
            "type": "radio",
            "option":[
                {"text":"男","value":"M"},
                {"text":"女","value":"F"}
        ],
            "regex":"^[MF]$"
        },
        {
            "name":"applicant.mobile",
            "text": "手机",
            "value":"",
            "type": "text",
            "regex":"^((13|14|15|17|18)(\d)(\*\*\*\*|\d{4})(\d{4,5}))?$"
        },
        {
            "name":"applicant.email",
            "text": "E-mail",
            "value":"",
            "type": "text",
            "regex":"^[\w\-\.]+@[a-zA-Z0-9]+(\-[a-zA-Z0-9]+)?(\.[a-zA-Z0-9]+(\-[a-zA-Z0-9]+)?)*\.[a-zA-Z]{2,4}$"
        },
        {
            "name":"applicant.provinceCode",
            "text": "投保人省份",
            "value":"",
            "type": "select",
            "option":[
                {"text":"请选择","value":""}
        ]
        },
        {
            "name":"applicant.cityCode",
            "text": "投保人城市",
            "value":"",
            "type": "select",
            "option":[
                {"text":"请选择","value":""}
        ]
        },
        {
            "name":"applicant.areaCode",
            "text": "投保人区县",
            "value":"",
            "type": "select",
            "option":[
                {"text":"请选择","value":""}
        ]
        },
        {
            "name":"applicant.address",
            "text": "投保人地址",
            "value":"",
            "type": "select",
            "option":[
                {"text":"请选择","value":""}
        ]
        }

],"checkvehicle":{
    "isNeed":"true",
    "message":"是否需要验车"
},"register":[
        {    "name":"register.name",
            "text": "车主姓名",
            "value":"陈跃军",
            "type": "text",
            "regex" : "^(?:[\u4e00-\u9fa5\u3400-\u4db5\u9fa6-\u9fbb\uf900-\uFA6A\uE815-\uE864·]|[a-zA-Z\s]){1,40}$"
        }
        ,{
            "name":"register.idType",
            "text": "证件类型",
            "value":"",
            "type": "select",
            "option":[
            {"text":"请选择","value":""},
            {"text":"居民身份证","value":"01"},
            {"text":"护照","value":"02"},
            {"text":"军官证","value":"03"},
            {"text":"驾驶证","value":"05"},
            {"text":"港澳回乡证或台胞证","value":"06"}
    ],
            "regex" : "^01|02|03|05|06$"
        }
        ,{
            "name":"register.idNo",
            "text": "证件号码",
            "value":"",
            "type": "text",
            "regex" : ""
        }
        ,{
            "name":"register.birthday",
            "text": "生日",
            "value":"",
            "type": "text",
            "regex" : "^(((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29)))?$"
        }

        ,{
            "name":"register.gender",
            "text": "性别",
            "value":"M",
            "type": "radio",
            "option":[
            {"text":"男","value":"M"},
            {"text":"女","value":"F"}
    ],
            "regex" : "^[MF]$"
        }
],"orderInfo":{
    "vehicle": {
        "frameNo": "LSGJR52U04S326239",
        "engineNo": "F16D3231390K",
        "licenseNo": "苏AP615W",
        "modelName": "别克SGM7161LX",
        "description": "三厢 手动档 舒适型",
        "seat": "5",
        "registerDate":"2004-11-03",
        "q2InputType":"1"
    },
    "insured": {
        "name": "陈跃军",
        "idNo": "",
        "email": "",
        "mobile": "",
        "birthday": "",
        "gender": "",
        "idType": ""
    },
    "register": {
        "name": "陈跃军",
        "idNo": "",
        "birthday": "",
        "gender": "M",
        "idType": ""
    },

    "bizConfig": {
        "beginDate":"2015-11-06",
        "endDate":"2016-11-05",
        "amount01":    "70200",
        "amount02": "2000000",
        "amount03": "0",
        "amount04": "20000",
        "amount05": "20000",
        "amount08": "0",
        "amount10": "0",
        "amount17": "0",
        "amount18": "0",
        "amount27": "1",
        "amount28": "1",
        "amount29": "0",
        "amount41": "0",
        "amount48": "0",
        "amount49": "1",
        "amount50": "0",
        "amount57": "0",
        "amount59": "0",
        "amount80": "0",
        "inputAmount": "70200"
    },
    "bizResult": {
        "premium01": "1023.28",
        "premium02": "2003.09",
        "premium03": "0",
        "premium04": "52.38",
        "premium05": "136.19",
        "premium08": "0",
        "premium10": "0",
        "premium17": "0",
        "premium18": "0",
        "premium27": "153.49",
        "premium28": "300.46",
        "premium29": "0",
        "premium41": "0",
        "premium48": "0",
        "premium49": "28.29",
        "premium50": "0",
        "premium57": "0",
        "premium59": "0",
        "premium80": "0",
        "totalPremium": "3697.18",
        "originalPremium": "5646.65",
        "savedPremium": "1949.47"
    },

    "forceResult": {
        "beginDate":"2015-11-06",
        "endDate":"2016-11-05",
        "forcePremium":"855",
        "taxPremium":"300",
        "totalPremium":"1155"
    },


    "floatNotice":{
        "bizNotice":"true",
        "forceNotice":"true",
        "notice":"1"
    },
    "isNeedSmsCode": "false"
},"otherInfo":{
    "isApplyBiz":"true",
    "isApplyForce":"true",
    "serverDate":"2015/11/05 20:42:13"
},"switches":{
    "isUseTaxPrice":"false",
    "isUpGradePMhasData":"0",
    "renewalConfirm":"0",
    "isNpsFlow":"false"
}}
/$

def x = new JsonSlurper().with {
    type = JsonParserType.LAX
    it
}.parseText str.tokenize('\n').collect { line ->
    !line.contains('regex') ? line :
            line[line.indexOf(':')+1..-1].with { regex ->
                def bbb = regex =~ /"(.*)"/
                "\"regex\" : \"${StringEscapeUtils.escapeJava(bbb[0][1])}\","
            }
}.join('\n')


println x.orderInfo.bizResult


